package com.kingzoder.food.common.base;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 统一响应结果
 *
 * @param <T> 响应数据类型
 * @author ZoderKing
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVO<T> implements Serializable {
    private int code;
    private boolean success = true;
    private String message;
    private T data;

    /**
     * 成功响应
     */
    public static <T> ResultVO<T> success(T data) {
        return new ResultVO<>(200, true, "success", data);
    }

    /**
     * 失败响应
     */
    public static <T> ResultVO<T> error(String message) {
        return new ResultVO<>(500, false, "操作失败", null);
    }

    /**
     * 失败响应
     */
    public static <T> ResultVO<T> error(int code, String message) {
        return new ResultVO<>(500, false, "操作失败", null);
    }
}
